﻿using System;
using System.Collections.Generic;


public class LessonCfgData : ImplData
{

	public class LessonCfg
	{
		public string lessonType = "";
		public string id = "";

	}

	private Dictionary<string, Dictionary<string, LessonCfg>> d = new Dictionary<string, Dictionary<string, LessonCfg>> ();

	protected override int Deserialize()
	{

		if (string.IsNullOrEmpty(jsonText))
			return -1;

		data = MiniJSON.Json.Deserialize(jsonText) as Dictionary<string, object>;

		foreach (var item in data) {
		
			Dictionary<string, LessonCfg> t = new Dictionary<string, LessonCfg> ();
			Dictionary<string, object> dict = item.Value as Dictionary<string, object>;
			foreach (var i in dict) {
			
				Dictionary <string, object> tmp = i.Value as Dictionary<string, object>;
				LessonCfg c = new LessonCfg ();
				c.lessonType = tmp ["type"].ToString ();
				c.id = tmp ["id"].ToString ();

				t.Add (i.Key, c);

			}

			d.Add (item.Key, t);

		}
			
		return 0;
	}
		
	public Dictionary<string, LessonCfg> GetLesson( string id )
	{
		if (d.ContainsKey (id))
			return d [id];
		else
			return null;
	}
		
	public Dictionary<string, LessonCfg> GetLessonByIdx( int idx )
	{
		if (idx > d.Count)
			return null;

		return GetLesson (idx.ToString ());
	}

	public int GetLessonCount()
	{
		return d.Count;
	}

}


